package middle;

import util.PrintUtils;

public class Solution_309 {
    public int maxProfit(int[] prices) {
        int[] array = new int[prices.length];
        for (int i = 1; i < prices.length; i++) {
            int max = Integer.MIN_VALUE;
            for (int j = i - 1; j >= 0; j--) {
                int num = prices[i] - prices[j] + (j >= 2 ? array[j - 2] : 0);
                max = Math.max(num, max);
            }
            array[i] = Math.max(max, array[i - 1]);
        }
        PrintUtils.arrayInt(array);
        return array[prices.length - 1];
    }

    public static void main(String[] args) {
        Solution_309 model = new Solution_309();
        System.out.println(model.maxProfit(new int[]{1,2,3,0,2}));
        System.out.println(model.maxProfit(new int[]{1}));
    }
}
